﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectSheduleAnalyst
{
    public partial class LessonCreationForm : Form
    {
        public LessonCreationForm()
        {
            InitializeComponent();

            this.Text = "Создание нового занятия";

            ChooseSubjectButton.BackColor = Color.Green;
            ChooseTeacherButton.Enabled = false;
            ChooseGroupButton.Enabled = false;
            ChooseClassButton.Enabled = false;


        }

        private DB_Access dba = new DB_Access();


        private void ChooseSubjectButton_Click(object sender, EventArgs e)
        {
            LessonCreationAssistForm LesCrAsF = new LessonCreationAssistForm();
            LesCrAsF.Owner = this;
            Data.Status = 1;
            //LesCrAsF.ShowDialog();

            if (LesCrAsF.ShowDialog() == DialogResult.OK)
            {
                ChooseSubjectButton.Enabled = false;
                ChooseSubjectButton.BackColor = Color.Blue;
                ChooseTeacherButton.Enabled = true;
                ChooseTeacherButton.BackColor = Color.Green;
            }
        }

        private void ChooseTeacherButton_Click(object sender, EventArgs e)
        {
            LessonCreationAssistForm LesCrAsF = new LessonCreationAssistForm();
            LesCrAsF.Owner = this;
            Data.Status = 2;
            //LesCrAsF.ShowDialog();
            if (LesCrAsF.ShowDialog() == DialogResult.OK)
            {
                ChooseTeacherButton.Enabled = false;
                ChooseTeacherButton.BackColor = Color.Blue;
                ChooseGroupButton.Enabled = true;
                ChooseGroupButton.BackColor = Color.Green;
            }
        }

        private void ChooseGroupButton_Click(object sender, EventArgs e)
        {
            LessonCreationAssistForm LesCrAsF = new LessonCreationAssistForm();
            LesCrAsF.Owner = this;
            Data.Status = 3;
            //LesCrAsF.ShowDialog();
            if (LesCrAsF.ShowDialog() == DialogResult.OK)
            {
                ChooseGroupButton.Enabled = false;
                ChooseGroupButton.BackColor = Color.Blue;
                ChooseClassButton.Enabled = true;
                ChooseClassButton.BackColor = Color.Green;
            }
        }

        private void ChooseClassButton_Click(object sender, EventArgs e)
        {
            LessonCreationAssistForm LesCrAsF = new LessonCreationAssistForm();
            LesCrAsF.Owner = this;
            Data.Status = 4;
            //LesCrAsF.ShowDialog();
            if (LesCrAsF.ShowDialog() == DialogResult.OK)
            {
                ChooseClassButton.Enabled = false;
                ChooseClassButton.BackColor = Color.Blue;
            }
        }

        public List<string> IDlist = new List<string>(); 

        private void CreateButton_Click(object sender, EventArgs e)
        {
            if (SubjectTextBox.Text != "" & TeacherTextBox.Text != "" & GroupTextBox.Text != "" &
                ClassTextBox.Text != "")
            {
                dba.MySQLquery(@"INSERT INTO LESSONS (SUBJECT_ , TEACHER_ , GROUP_ , CLRT_ ) VALUES
                    ('" + IDlist[0] + "','"
                               + IDlist[1] + "','"
                               + IDlist[2] + "','"
                               + IDlist[3] + "')");
                IDlist.Clear();
                this.Close();
            }

            else
            {
                MessageBox.Show("Для создания занятия запоните все поля");
            }

        }

        private void CloseButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ClearLessonInfoButton_Click(object sender, EventArgs e)
        {
            IDlist.Clear();
            SubjectTextBox.Clear();
            TeacherTextBox.Clear();
            GroupTextBox.Clear();
            ClassTextBox.Clear();

            ChooseSubjectButton.Enabled = true;
            ChooseSubjectButton.BackColor = Color.Green;
            
            ChooseTeacherButton.BackColor = Color.Empty;
            ChooseGroupButton.BackColor = Color.Empty;
            ChooseClassButton.BackColor = Color.Empty;
            
            ChooseTeacherButton.Enabled = false;
            ChooseGroupButton.Enabled = false;
            ChooseClassButton.Enabled = false;
        }
    }
}
